USE [ERPSIADB]
GO

/****** Object:  StoredProcedure [dbo].[SP_AGREGAR_BODEGA]    Script Date: 10/30/2010 12:47:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[SP_AGREGAR_BODEGA] 
	-- Add the parameters for the stored procedure here
	@Codigo varchar(20),
	@Nombre varchar(40),
	@CuentaVentas int,
	@CuentaCompras int,
	@CuentaInv int,
	@CuentaCostoV int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO Bodega 
	(CodigoBodega, Nombre, IdCuentaVentas, IdCuentaCompras, IdCuentaInventario, IdCuentaCostoVentas)
	VALUES
	(@Codigo, @Nombre, @CuentaVentas, @CuentaCompras, @CuentaInv, @CuentaCostoV);
	
	INSERT INTO BodegaArticulo
	(IdBodega, IdArticulo, IdCuentaVentas, IdCuentaCompras, IdCuentaInventario, IdCuentaCostoVentas)
	SELECT Bodega.IdBodega, Articulo.IdArticulo, Bodega.IdCuentaVentas, Bodega.IdCuentaCompras, Bodega.IdCuentaInventario,
	Bodega.IdCuentaCostoVentas
	FROM Bodega, Articulo
	WHERE Bodega.IdBodega = IDENT_CURRENT('Bodega')
	
	SELECT IDENT_CURRENT('Bodega') AS IdBodega	
END



GO


